
/****** Object:  StoredProcedure [dbo].[ws_r_klientas_i]    Script Date: 10/19/2013 09:22:25 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

--IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'ws_r_klientas_i')
DROP PROCEDURE ws_r_klientas_i
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[ws_r_klientas_i] (
	@kodas_ks varchar(12),
	@pav varchar(70),
	@im_kodas varchar(13),
	@pvm_kodas varchar(25),
	@adr varchar(40),
	@rezervas varchar(40),
	@pastas varchar(9),
	@kodas_vs varchar(12),
	@atstovas varchar(40),
	@e_mail varchar(40),
	@tel varchar(40),
	@mob_tel varchar(40),
	@fax_num varchar(40),
	@pozymis char(1)
	)
AS
BEGIN
	
	
	If exists(SELECT * FROM n08_klij where n08_kodas_ks = @kodas_ks) and @pozymis='1'
		begin
			update n08_klij set			
				n08_pav=@pav,
				n08_im_kodas=@im_kodas,
				n08_pvm_kodas=@pvm_kodas,
				n08_adr=@adr,
				n08_rezervas=@rezervas,
				n08_pastas=@pastas,
				n08_kodas_vs=@kodas_vs,
				n08_atstovas=@atstovas,
				n08_e_mail=@e_mail,
				n08_tel=@tel,
				n08_mob_tel=@mob_tel,
				n08_fax_num=@fax_num
			where n08_kodas_ks = @kodas_ks
			
			insert into #ttresult (res) VALUES ('')
		end
	else
		begin
			If exists(SELECT * FROM n08_klij where n08_kodas_ks = @kodas_ks)
				begin
					insert into #ttresult (res) VALUES ('update not allowed')
				end
			else
				begin
					insert INTO n08_klij (n08_kodas_ks,
						n08_pav,
						n08_im_kodas,
						n08_pvm_kodas,
						n08_adr,
						n08_rezervas,
						n08_pastas,
						n08_kodas_vs,
						n08_atstovas ,
						n08_e_mail,
						n08_tel,
						n08_mob_tel,
						n08_fax_num,
						n08_rusis,
						n08_kodas_ds,
						n08_kodas_xs_t,
						n08_kodas_xs_p,
						n08_addusr
						) 
					values (@kodas_ks,
							@pav,
							@im_kodas,
							@pvm_kodas,
							@adr,
							@rezervas,
							@pastas,
							@kodas_vs,
							@atstovas ,
							@e_mail,
							@tel,
							@mob_tel,
							@fax_num,
							3,
							'PT001',
							'PVM',
							'PVM',
							'RIVILE_WS'
					)
					
					insert into #ttresult (res) VALUES ('')
				end
		end
END

GO

